package com.bjf.util;

import org.springframework.context.ApplicationContext;

import com.bjf.exception.BJFException;

public class ContextUtil {
	private static ApplicationContext context;

	public static ApplicationContext getContext() {
		return context;
	}
	
	public static <T> T getBean(String beanId,Class<T> classType){
		//return (T)context.getBean(beanId);
		return classType.cast(context.getBean(beanId));
	}

	public static Object getBean(String beanId) throws BJFException {
		Object bean = context.getBean(beanId);
		if (bean == null)
			throw new BJFException("bean id = " + bean + " not found");
		return bean;
	}

	public static void setContext(ApplicationContext ctx) {
		context = ctx;
	}
}